package admin

import "object/go_cms/models"

type LinkAdminController struct {
	BaseAdminController
	models models.LinksModels
}

// @router /admin/link/indexUI [get]
func (c *LinkAdminController) IndexUI() {
	c.TplAdmin("link/index")
}

// @router /admin/link/addUI [get]
func (c *LinkAdminController) AddUI() {
	c.TplAdmin("link/add")
}

// @router /admin/link/editUI [get]
func (c *LinkAdminController) EditUI() {
	c.TplAdmin("link/edit")
}

// @router /admin/link/get [get,post]
func (c *LinkAdminController) Get() {
	id, _ := c.GetInt("link_id")
	c.Res.Data, _ = c.models.Get(id)
	c.Res.Code = 1
	c.Json(c.Res)
}

// @router /admin/link/query [get,post]
func (c *LinkAdminController) Query() {
	c.Res.Data, _ = c.models.Query()
	c.Json(c.Res)
}

// @router /admin/link/add [post]
func (c *LinkAdminController) Add() {
	c.Res.Code = 1
	c.Res.Msg = "添加成功"
	maps := c.GetParamMap()
	_, err := c.models.Insert(maps)
	if err != nil {
		c.Res.Code = 0
		c.Res.Msg = err.Error()
	}
	c.Json(c.Res)
}

// @router /admin/link/edit [post]
func (c *LinkAdminController) Edit() {
	c.Res.Code = 1
	c.Res.Msg = "修改成功"
	maps := c.GetParamMap()
	_, err := c.models.Update(maps)
	if err != nil {
		c.Res.Code = 0
		c.Res.Msg = err.Error()
	}
	c.Json(c.Res)
}

// @router /admin/link/delete [post]
func (c *LinkAdminController) Delete() {
	c.Res.Code = 1
	c.Res.Msg = "删除成功"
	id, _ := c.GetInt("link_id")
	_, err := c.models.Delete(id)
	if err != nil {
		c.Res.Code = 0
		c.Res.Msg = err.Error()
	}
	c.Json(c.Res)
}
